package com.lyn.pluginbazaar.controller;

import com.lyn.pluginbazaar.annotation.Login;
import com.lyn.pluginbazaar.api.UserAdapter;
import com.lyn.pluginbazaar.entity.LoginUser;
import com.lyn.pluginbazaar.entity.PagingQuery;
import com.lyn.pluginbazaar.entity.Result;
import com.lyn.pluginbazaar.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "用户")
@CrossOrigin
@RestController
public class UserController implements UserAdapter {

    @Autowired
    private UserService userService;


    @PostMapping(value = "/login")
    @Override
    public Result login(@RequestBody LoginUser loginUser, HttpServletRequest request, HttpServletResponse response) {
        return userService.login(loginUser,request,response);
    }

    @Login
    @PostMapping(value = "/logOut")
    @Override
    public Result logOut(HttpServletRequest request,HttpServletResponse response) {
        return userService.logOut(request, response);
    }

    @GetMapping(value = "/getCheckCode")
    @Override
    public Result getCheckCode(HttpServletRequest request, HttpServletResponse response) {
        return userService.getCheckCode(request, response);
    }
    @Login
    @GetMapping(value = "/checkLogin")
    @Override
    public Result checkLogin(HttpServletRequest request, HttpServletResponse response) {
        return userService.checkLogin(request, response);
    }

    @Login
    @Override
    public Result pagingQuery(PagingQuery pagingQuery) {
        return null;
    }

    @Login
    @PostMapping(value = "/count")
    @Override
    public Result count(@RequestBody PagingQuery pagingQuery) {
        return userService.count(pagingQuery);
    }
}
